Skip to content

Implement tick() for aarch64 on non-Apple platforms#854

Merged
mjp41 merged 3 commits into
microsoft:mainfrom
mjp41:arm_tick
Jun 8, 2026
Merged

Implement tick() for aarch64 on non-Apple platforms#854
mjp41 merged 3 commits into
microsoft:mainfrom
mjp41:arm_tick

Conversation

@mjp41

@mjp41 mjp41 commented Jun 7, 2026

Copy link
Copy Markdown
Member

The aarch64 tick() implementation was previously gated on APPLE, leaving Linux (and other non-Apple aarch64 platforms) with no cycle counter. On those platforms the generic AAL fell through to __builtin_readcyclecounter(), which on aarch64 emits mrs PMCCNTR_EL0; that register is not accessible from EL0 on Linux and would SIGILL.

CNTVCT_EL0 is readable from EL0 on Linux, FreeBSD, and other mainstream aarch64 OSes (the kernel sets CNTKCTL_EL1.EL0VCTEN), so the same implementation Apple uses works everywhere on aarch64.

  • aal_arm.h: extend tick() to all SNMALLOC_VA_BITS_64 targets and add an MSVC path using _ReadStatusReg(ARM64_CNTVCT). Drop NoCpuCycleCounters for 64-bit ARM (it remains for 32-bit ARM).
  • aal.h: exclude aarch64 from the __builtin_readcyclecounter() path so it always routes through Arch::tick().

mjp41 and others added 3 commits June 7, 2026 11:01
The aarch64 tick() implementation was previously gated on __APPLE__,
leaving Linux (and other non-Apple aarch64 platforms) with no cycle
counter. On those platforms the generic AAL fell through to
__builtin_readcyclecounter(), which on aarch64 emits
`mrs PMCCNTR_EL0`; that register is not accessible from EL0 on Linux
and would SIGILL.

CNTVCT_EL0 is readable from EL0 on Linux, FreeBSD, and other
mainstream aarch64 OSes (the kernel sets CNTKCTL_EL1.EL0VCTEN), so
the same implementation Apple uses works everywhere on aarch64.

- aal_arm.h: extend tick() to all SNMALLOC_VA_BITS_64 targets and add
  an MSVC path using _ReadStatusReg(ARM64_CNTVCT). Drop
  NoCpuCycleCounters for 64-bit ARM (it remains for 32-bit ARM).
- aal.h: exclude aarch64 from the __builtin_readcyclecounter() path so
  it always routes through Arch::tick().

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ARM64_CNTVCT is not always available as a predefined macro. Use the
explicit ARM64_SYSREG(3, 3, 14, 0, 2) encoding for CNTVCT_EL0 instead,
and include <intrin.h> so _ReadStatusReg and ARM64_SYSREG are declared.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mjp41 mjp41 merged commit 3d49eee into microsoft:main Jun 8, 2026
198 checks passed
@mjp41 mjp41 deleted the arm_tick branch June 8, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant